using System.Configuration;
using System.IO;
using System.Collections.Generic;

namespace mock_ehr_lib.Data.LookupServices
{
    public class LOINCLookupService : ILookupService
    {
        private static LOINCLookupService _instance = null;
        private Dictionary<string, string> _lookup;
        private LOINCLookupService()
        {
            var filename = ConfigurationManager.AppSettings["loincFilename"];
            _lookup = new Dictionary<string, string>();
            var lines = File.ReadAllLines(filename);
            foreach(var line in lines)
            {
                var fields = line.Split('\t');
                var code = fields[0].Replace("\"", "");
                var description = fields[1].Replace("\"", "");
                _lookup.Add(code, description);
            }
        }

        public static LOINCLookupService Instance
        {
            get
            {
                return _instance ?? (_instance = new LOINCLookupService());
            }
        }

        public string GetDescriptionByCode(string code)
        {
            return _lookup[code];
        }
    }
}